//
//  AssesmentController.m
//  EducationAdminClient 1111111111 23222
//
//  Created by 孙添凤 on 16/11/8.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "AssesmentController.h"
#import "KeyValuesClass.h"
#import "EditModel.h"

@interface AssesmentController ()<UITextViewDelegate>
@property(nonatomic,strong)UIScrollView *sv;

@property (nonatomic, strong) NSMutableArray *StardataArray;//选星星后某个数组 默认进入5颗星
@property (nonatomic, strong) NSMutableArray *allStarArray;
@property (nonatomic, assign) NSInteger lastBtnY;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UILabel *placeHolder;
@property (nonatomic, strong) NSMutableArray *btnArr;
@property (nonatomic, strong) UIButton *sureEvalute;
@property (nonatomic, strong) NSArray *labelArr;
@property (nonatomic, strong) NSArray *stageArr;
@property (nonatomic, strong) UILabel *starBottomLabel;
@property (nonatomic, strong) NSArray *fieldSetArr;
@property (nonatomic, strong) NSArray *starArr;//星星数组
@property (nonatomic, strong) NSMutableArray *describeArr;//描述数组
@property (nonatomic ,strong) NSMutableArray *seleBtnArr;//选择描述的数组
@property (nonatomic ,strong) NSMutableDictionary *mutDic;;//选择描述的字典
@property (nonatomic ,strong) NSMutableDictionary *sendDic;
@property (nonatomic ,strong) NSMutableDictionary *descKeyDic;
@property (nonatomic ,strong) NSMutableArray *descKeyArr;
@property (nonatomic ,strong) NSString *starID;
@property (nonatomic ,strong) NSString *stageID;
@property (nonatomic ,strong) NSString *relationId;
@property (nonatomic ,strong) NSMutableArray *hiddenArr;
@property (nonatomic ,strong) KeyValuesClass *keyValueClass;
@property (nonatomic ,strong) UIView *l1;
@property (nonatomic ,strong) UIView *l2;

@property(nonatomic,retain)  UIAlertView           *alert;
@property(nonatomic,assign) NSInteger starNUm;

@end

@implementation AssesmentController

- (NSMutableArray *)StardataArray
{
    if (!_StardataArray) {
        _StardataArray = [NSMutableArray array];
    }
    return _StardataArray;
}

- (NSMutableArray *)allStarArray
{
    if (!_allStarArray) {
        _allStarArray = [NSMutableArray array];
    }
    return _allStarArray;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tNum=0;
    [self createLeftNavBar];
    [self dataRequest];
    
    _describeArr =[NSMutableArray array];
    _seleBtnArr =[NSMutableArray array];
    _descKeyArr =[NSMutableArray array];
    self.view.backgroundColor =[UIColor whiteColor];
    _mutDic =[NSMutableDictionary dictionary];
    _sendDic =[NSMutableDictionary dictionary];
    _descKeyDic =[NSMutableArray array];
    _hiddenArr =[NSMutableArray array];
    _keyValueClass = [[KeyValuesClass alloc]init];
//    _labelArr =@[@[@"上课无计划",@"备课不认真",@"迟到",@"早退",@"上课玩手机"],@[@"备课不认真",@"上课缺少互动",@"上课玩手机"],@[@"耐心负责",@"上课玩手机",@"着装邋遢"@"语速过快"],@[@"备课认真",@"教学专业",@"讲解清晰"@"穿着正式",@"着装邋遢",@"语速过快"],@[@"备课认真",@"教学专业",@"穿着正式",@"讲解清晰",@"语速过快"]];
//    _stageArr = @[@"差",@"不满意",@"一般，需进步",@"满意，仍需进步",@"非常满意，无可挑剔"];
//    _allStarArray = [NSMutableArray arrayWithArray:_labelArr];
//    _StardataArray = [NSMutableArray arrayWithArray:_allStarArray[4]];
    _btnArr = [NSMutableArray array];
//    [self creatUI];
    
    //注册通知,监听键盘弹出事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:)
                                                 name:UIKeyboardWillShowNotification object:nil];
    
    //注册通知,监听键盘消失事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHidden)
                                                 name:UIKeyboardWillHideNotification object:nil];
}

-(void)creatUI{
    

    _sv =[[UIScrollView alloc]init];
    [self.view addSubview:_sv];
    [_sv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    _sv.contentSize = CGSizeMake(KWIDTH, KWIDTH+300);
    _sv.userInteractionEnabled = YES;
    
    UILabel *niming =[[UILabel alloc]init];
    [niming sizeToFit];
    [_sv addSubview:niming];
    [niming mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.height.equalTo(@(13));
        make.top.equalTo(_sv.mas_top).offset(16);
    }];
    niming.textColor =[UIColor colorWithHex:0xb6b6b6];
    niming.font =[UIFont systemFontOfSize:13];
    niming.text = @"匿名评价";
    
    [self StarView];
    _starBottomLabel =[[UILabel alloc]init];
    [_starBottomLabel sizeToFit];
    [_sv addSubview:_starBottomLabel];
    [_starBottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.height.equalTo(@(13));
        make.top.equalTo(_sv.mas_top).offset(40+12.5+31);
    }];
    _starBottomLabel.textColor =[UIColor colorWithHex:0xb6b6b6];
    _starBottomLabel.font =[UIFont systemFontOfSize:13];
    
    NSArray *arr = [_fieldSetArr[1]objectForKey:@"dicList"];
    NSDictionary *dd = arr[0];
    _starBottomLabel.text = [dd objectForKey:@"DIC_NAME"];
    
    _l1=[[UIView alloc]init];
    [_sv addSubview:_l1];
    [_l1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(33/2);
        make.right.equalTo(self.view.mas_centerX).offset(-4);
        make.height.equalTo(@(0.5));
        make.top.equalTo(_starBottomLabel.mas_bottom).offset(17+5);
    }];
    _l1.backgroundColor =[UIColor colorWithHex:0xdedede];
    
    _l2=[[UIView alloc]init];
    [_sv addSubview:_l2];
    [_l2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(-33/2);
        make.left.equalTo(self.view.mas_centerX).offset(4);
        make.height.equalTo(@(0.5));
        make.top.equalTo(_starBottomLabel.mas_bottom).offset(17+5);
    }];
    _l2.backgroundColor =[UIColor colorWithHex:0xdedede];
    
    UIImageView *top =[[UIImageView alloc]init];
    [_sv addSubview:top];
    [top mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_starBottomLabel.mas_bottom).offset(17);
        make.height.equalTo(@(5));
        make.width.equalTo(@(8));
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    top.image =[UIImage imageNamed:@"horn"];
    
     [self varietyLabel];

    
}

-(void)varietyLabel{
    _l2.hidden = NO;
    _l1.hidden = NO;
    if(_btnArr.count>0){
        for(UIButton *btn in _btnArr){
            [btn removeFromSuperview];
        }
    }
    
    for (int i = 0; i < _StardataArray.count; i ++)
    {
        //        Area *are = cell_Array[i];
        NSDictionary *dic =_StardataArray[i];
        NSString *name = [dic objectForKey:@"DIC_NAME"];
        static UIButton *recordBtn =nil;
        
        UIButton *btn = [[UIButton alloc]init];
#pragma mark - 选项卡按钮文字颜色：灰色b5b5b5
        [btn setTitleColor:[UIColor colorWithHex:0xb5b5b5] forState:UIControlStateNormal];
        btn.titleLabel.font =[UIFont systemFontOfSize:16];
        btn.layer.borderColor =[[UIColor colorWithHex:0xdedede]CGColor];
        btn.layer.borderWidth = 1;
        btn.layer.cornerRadius = 1;
        btn.tag = 10000+i;
        [_btnArr addObject:btn];
        btn.selected = NO;
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.backgroundColor =[UIColor whiteColor];
        
        
        CGRect rect = [name boundingRectWithSize:CGSizeMake(KWIDTH-20, 30) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:btn.titleLabel.font} context:nil];
        rect.size.width= rect.size.width+22;
        if (i == 0)
        {
            btn.frame =CGRectMake(31.5, 157, rect.size.width, 34);
        }
        else{
            CGFloat yuWidth = KWIDTH-40-recordBtn.frame.origin.x -recordBtn.frame.size.width;
            if (yuWidth >= rect.size.width) {//63 为判断每行的最想距离
                btn.frame =CGRectMake(recordBtn.frame.origin.x +recordBtn.frame.size.width + 20, recordBtn.frame.origin.y, rect.size.width, 34);
            }else{
                btn.frame =CGRectMake(31.5, recordBtn.frame.origin.y+recordBtn.frame.size.height+17, rect.size.width, 34);
            }
            
        }
        [btn setTitle:name forState:UIControlStateNormal];
        [_sv addSubview:btn];
        
        recordBtn = btn;
        if(i==_StardataArray.count-1){
            _lastBtnY = btn.frame.origin.y+34;
        }
    }
    if(_textView==nil){
       _textView =[[UITextView alloc]init];
        
    }
    if(_sureEvalute==nil){
      _sureEvalute =[[UIButton alloc]init];
    }
    
    if(_lastBtnY<1){
        _l2.hidden = YES;
        _l1.hidden = YES;
        _textView.frame = CGRectMake(16.5, 110, KWIDTH-33, 130);
    }else{
        _textView.frame = CGRectMake(16.5, _lastBtnY+43, KWIDTH-33, 130);
    }
    
    
    [_sv addSubview:_textView];
    _textView.delegate = self;
    _textView.layer.borderColor =[[UIColor colorWithHex:0xdedede]CGColor];
    _textView.layer.borderWidth = 0.5;
    _textView.layer.cornerRadius = 1.5;
    _textView.backgroundColor =[UIColor clearColor];
    _textView.font =[UIFont systemFontOfSize:16];
    
    if(_placeHolder==nil){
        _placeHolder =[[UILabel alloc]init];
    }
    
    if(_lastBtnY<1){
       _placeHolder.frame =CGRectMake(16.5+6, 110+8, 200, 16);
    }else{
        _placeHolder.frame =CGRectMake(16.5+6, _lastBtnY+43+8, 200, 16);
    }
    
        [_sv addSubview:_placeHolder];
    _placeHolder.textColor =[UIColor colorWithHex:0xb6b6b6];
    _placeHolder.font =[UIFont systemFontOfSize:16];
    _placeHolder.text = @"将通知到校区工作人员";
    
    
    _sureEvalute.frame = CGRectMake(16.5, _textView.frame.origin.y+130+20, KWIDTH-33, 35);
    [_sv addSubview:_sureEvalute];
    [_sureEvalute setBackgroundImage:[UIImage imageNamed:@"publish_btn_normal"] forState:UIControlStateNormal];
    [_sureEvalute setTitle:@"确认评价" forState:UIControlStateNormal];
    [_sureEvalute setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _sureEvalute.titleLabel.font =[UIFont systemFontOfSize:15];
    [_sureEvalute addTarget:self action:@selector(sureBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_sureEvalute setBackgroundImage:[UIImage imageNamed:@"publish_btn_press"] forState:UIControlStateHighlighted];
    
}
#pragma mark *****-确认评价点击
-(void)sureBtnClick:(UIButton *)btn{
    [self addRequest];
}

-(void)btnClick:(UIButton *)btn{
    NSInteger i = btn.tag-10000;
    if(btn.selected){
        btn.selected = NO;//取消点击状态
#pragma mark - 灰色边框颜色：dedede
        btn.layer.borderColor =[[UIColor colorWithHex:0xb5b5b5]CGColor];
        [btn setTitleColor:[UIColor colorWithHex:0xb5b5b5] forState:UIControlStateNormal];
        [_mutDic removeObjectForKey:[NSString stringWithFormat:@"%ld",i]];
    }else{
        btn.selected = YES;//点击状态
        btn.layer.borderColor =[[UIColor colorWithHex:0xff8a18]CGColor];
        [btn setTitleColor:[UIColor colorWithHex:0xff8a18] forState:UIControlStateNormal];
        [_mutDic setObject:_StardataArray[i] forKey:[NSString stringWithFormat:@"%ld",i]];
        
    }
}

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    _placeHolder.hidden = YES;
    return YES;
}

-(void)textViewDidEndEditing:(UITextView *)textView{
    if([textView.text isEqualToString:@""]){
       _placeHolder.hidden = NO;
    }
}
//星星
-(void)StarView{
    
    UIView *starBack =[[UIView alloc]init];
    [_sv addSubview:starBack];
    [starBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.equalTo(@(29*5+10*4));
        make.top.equalTo(_sv.mas_top).offset(40);
        make.height.equalTo(@(29));
    }];
    
    for(int i=0;i<5;i++){
        UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake((29+10)*i, 0, 29, 29)];
        [starBack addSubview:img];
        img.image =[UIImage imageNamed:@"already_press"];
        UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
        [img addGestureRecognizer:tap];
        img.tag = 1000+i;
        img.userInteractionEnabled = YES;
    }
    
}

// 键盘弹出时调用方法
-(void)keyboardDidShow:(NSNotification *)notification{
    NSDictionary* info = [notification userInfo];
    //kbSize即為鍵盤尺寸 (有width, height)
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;//得到鍵盤的高度
    if(_textView.frame.origin.y+130>KHEIGHT-kbSize.height){
        _sv.contentOffset=CGPointMake(0, 100);
    }
    
}

//键盘消失时调用
-(void)keyboardWillHidden{
    
    _sv.contentOffset=CGPointMake(0, 0);
    
}


-(void)dataRequest{
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    [parmas setObject:userName() forKey:@"loginName"];
    [parmas setObject:passWord() forKey:@"password"];
    
    NSString *path2;
    
    NSString *path3;
    
    NSDictionary *saveDic;
    
    
    
    NSString *requestStr;
    //    pageId=240&tableId=70&mainId=75&mainTableId=19&mainPageId=152
    
    NSString *btnType = [NSString stringWithFormat:@"%@", [self.buttonDIc valueForKey:@"buttonType"]];
    if(![btnType isEqualToString:@"18"]&&![btnType isEqualToString:@"12"]&&![btnType isEqualToString:@"15"]){
        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, ADDMF_URL];
        NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
        [parmas setObject:strTnum forKey:@"tNumber"];
        
        path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
        
        path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listForAdd%@%@.plist", self.tableId, self.pageId]];
        
        saveDic = [[NSDictionary alloc]initWithContentsOfFile:path3];
        
        if([self.buttonDIc valueForKey:@"startTurnPage"])[parmas setObject:[self.buttonDIc valueForKey:@"startTurnPage"] forKey:@"pageId"];
        [parmas setObject:self.tableId forKey:@"tableId"];
        if([saveDic valueForKey:@"alterTime"])
        {
            [parmas setObject:[saveDic valueForKey:@"alterTime"] forKey:@"alterTime"];
        }else{
            [parmas setObject:@"" forKey:@"alterTime"];
        }
        
    }else if([[NSString stringWithFormat:@"%@", [self.buttonDIc valueForKey:@"buttonType"]]isEqualToString:@"12"]||[[NSString stringWithFormat:@"%@", [self.buttonDIc valueForKey:@"buttonType"]]isEqualToString:@"15"]){
        [parmas setObject:[_buttonDIc objectForKey:@"startTurnPage"] forKey:@"pageId"];
        [parmas setObject:self.tableId forKey:@"tableId"];
        
        [parmas setObject:[_buttonDIc valueForKey:@"tableId"] forKey:@"mainTableId"];
        [parmas setObject:self.pageId forKey:@"mainPageId"];
        
        [parmas setObject:[NSString stringWithFormat:@"%@", [_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]]] forKey:@"mainId"];
        
        NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
        [parmas setObject:strTnum forKey:@"tNumber"];
        
        [parmas setObject:@"2222211" forKey:@"alterTime"];
        
        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, UPDATEMF_URL];
        
    }else{
        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, RELATIONADD_URL];
        [parmas setObject:[_buttonDIc objectForKey:@"startTurnPage"] forKey:@"pageId"];
        [parmas setObject:[_buttonDIc valueForKey:@"tableId"] forKey:@"tableId"];
        
        [parmas setObject:self.tableId forKey:@"mainTableId"];
        [parmas setObject:self.pageId forKey:@"mainPageId"];
        
        [parmas setObject:[NSString stringWithFormat:@"%@", [_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]]] forKey:@"mainId"];
        NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
        [parmas setObject:strTnum forKey:@"tNumber"];
        
        path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
        
        path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listForAdd%@%@.plist", self.tableId, self.pageId]];
        
        saveDic = [[NSDictionary alloc]initWithContentsOfFile:path3];
        
        if([saveDic valueForKey:@"alterTime"])
        {
            [parmas setObject:[saveDic valueForKey:@"alterTime"] forKey:@"alterTime"];
        }else{
            [parmas setObject:@"" forKey:@"alterTime"];
        }
        
    }
    
    [parmas setObject: getSessionId() forKey:@"sessionId"];
    
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        
        if(data!=nil&&!error){
            
            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            if ([obj valueForKey: @"promptMessage"]) {
                [[NSNotificationCenter defaultCenter]postNotificationName:@"relogin" object:@"relogin"];
                
            }
            
            NSLog(@"%@",obj);
            _fieldSetArr= [[obj objectForKey:@"pageSet"] objectForKey:@"fieldSet"];
            _starArr = [_fieldSetArr[0] objectForKey:@"dicList"];
            
            NSArray *starEvaArr = [_fieldSetArr[3] objectForKey:@"dicList"];
            
            NSMutableArray *one =[NSMutableArray array];
            NSMutableArray *two =[NSMutableArray array];
            NSMutableArray *three =[NSMutableArray array];
            NSMutableArray *four =[NSMutableArray array];
            NSMutableArray *five =[NSMutableArray array];
            
            for(NSDictionary *dic in starEvaArr){
                if([[dic objectForKey:@"DIC_REMARK"] isEqualToString:@"一星"]){
                    [one addObject:dic];
                }else if ([[dic objectForKey:@"DIC_REMARK"] isEqualToString:@"二星"]){
                    [two addObject:dic];
                }else if ([[dic objectForKey:@"DIC_REMARK"] isEqualToString:@"三星"]){
                    [three addObject:dic];
                }else if ([[dic objectForKey:@"DIC_REMARK"] isEqualToString:@"四星"]){
                    [four addObject:dic];
                }else if ([[dic objectForKey:@"DIC_REMARK"] isEqualToString:@"五星"]){
                    [five addObject:dic];
                }
            }
            [_describeArr addObject:one];
            [_describeArr addObject:two];
            [_describeArr addObject:three];
            [_describeArr addObject:four];
            [_describeArr addObject:five];
            _allStarArray =[NSMutableArray arrayWithArray:_describeArr];
            _StardataArray = [NSMutableArray arrayWithArray:_allStarArray[4]];
//            _descKeyDic = _fieldSetArr[3];
            NSLog(@"%@",_detailDic);
            _starNUm = 5;
            NSArray *starArr =[_fieldSetArr[0] objectForKey:@"dicList"];
            
            //起始星级取数组最后一个（如果最后一个是五星的话）修改这里
            _starID = [[starArr lastObject] objectForKey:@"DIC_ID"];
            
            NSArray *stageArr =[_fieldSetArr[1] objectForKey:@"dicList"];
            
            _stageID =[stageArr[0] objectForKey:@"DIC_ID"];
            self.relationId = [NSString stringWithFormat:@"%@", [[obj objectForKey:@"pageSet"] valueForKey:@"relationFieldId"]];
            
            NSArray *arrHiddenText = [[obj objectForKey:@"pageSet"]valueForKey:@"hideFieldSet"];
            
            for (NSDictionary *dic in arrHiddenText) {
                EditModel *model = [[EditModel alloc]init];
                model = [model initWithDictionary:dic error:nil];
                [_hiddenArr addObject:model];
            }
            // 数据处理，当没问题的情况下
            //            _itemDic = [obj valueForKey:@"dataInfo"];
            //            [self.tbView reloadData];
            [self creatUI];
        }else{
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
            
        }
        
        
    }];
}


//点击屏幕空白处
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //回收键盘，两者方式
    //UITextView *textView = (UITextView*)[self.view viewWithTag:1001];
    //[textView resignFirstResponder];
    [self.view endEditing:YES];
    NSLog(@"touch");
}


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    if([text isEqualToString:@"\n"]) {
        
        [textView resignFirstResponder];
        
        return NO;
        
    }
    
    return YES;
    
}

-(void)tapClick:(UITapGestureRecognizer *)tap{
    NSInteger a= tap.view.tag-1000+1;
    _starNUm = a;
    [_mutDic removeAllObjects];
    [_StardataArray removeAllObjects];
    _StardataArray = [NSMutableArray arrayWithArray:_allStarArray[a-1]];
//    _descKeyDic = _descKeyArr[a-1];
    [self varietyLabel];
    
    for(int i=0;i<5;i++){
        UIImageView *img =(UIImageView *)[self.view viewWithTag:1000+i];
        if(i<a){
            img.image =[UIImage imageNamed:@"already_press"];
        }else{
            img.image =[UIImage imageNamed:@"already"];
        }
    }
    NSArray *arr = [_fieldSetArr[1]objectForKey:@"dicList"];
    NSInteger arrconut = arr.count;
    NSDictionary *dd = arr[arrconut-a];
    _starBottomLabel.text = [dd objectForKey:@"DIC_NAME"];
    NSArray *starArr =[_fieldSetArr[0] objectForKey:@"dicList"];
    //星级评价数据字典顺序修改这里
    _starID = [starArr[a-1] objectForKey:@"DIC_ID"];
    NSArray *stageArr =[_fieldSetArr[1] objectForKey:@"dicList"];
    _stageID = [stageArr[5-a] objectForKey:@"DIC_ID"];
}

#pragma mark - ADDReq
-(void)addRequest{
    //    _sendMutDic = [[NSMutableDictionary alloc]init];
    //    NSDictionary *dic= [_filedArr objectAtIndex:focusTextField.indexPath.row];
    //
    _sureEvalute.userInteractionEnabled = NO;
    [_sendDic setObject:userName() forKey:@"loginName"];
    [_sendDic setObject:passWord() forKey:@"password"];
    [_sendDic setObject:[self.buttonDIc valueForKey:@"startTurnPage"] forKey:@"pageId"];
    [_sendDic setObject:[_buttonDIc objectForKey:@"tableId"] forKey:@"tableId"];
    [_sendDic setObject:@"1" forKey:@"source"];
    if (getSessionId()) {
        [_sendDic setObject: getSessionId() forKey:@"sessionId"];
    }
    NSDictionary *teacherSendDic = [_fieldSetArr lastObject];
    NSString *teacherSendMongoName = [NSString stringWithFormat:@"%@", [teacherSendDic valueForKey:@"montageName"]];
    [_sendDic setObject:[NSString stringWithFormat:@"%@", [teacherSendDic valueForKey:@"true_defaultShowValName"]] forKey:teacherSendMongoName];
    //*** keyStr
    
    NSString *pageId= [_buttonDIc objectForKey:@"startTurnPage"];
    //*** change the tableId
    NSString *tableId= [_buttonDIc objectForKey:@"tableId"];
    
    NSArray *selarray = [_mutDic allValues];
    NSMutableArray *descArr =[NSMutableArray array];
    for(NSDictionary *dic in selarray){
        NSString *str = [dic objectForKey:@"DIC_ID"];
        [descArr addObject:str];
    }
    NSString *descStr = [descArr componentsJoinedByString:@","];
    [_sendDic setObject: descStr forKey:[NSString stringWithFormat:@"%@_dicMany",[_fieldSetArr[3] objectForKey:@"montageName"]]];//选择btn
    [_sendDic setObject:_textView.text forKey:[_fieldSetArr[2] objectForKey:@"montageName"]];
    [_sendDic setObject:[NSString stringWithFormat:@"%@",_starID] forKey:[_fieldSetArr[0] objectForKey:@"montageName"]];
    [_sendDic setObject:[NSString stringWithFormat:@"%@",_stageID] forKey:[_fieldSetArr[1] objectForKey:@"montageName"]];
    [_sendDic setObject:[NSString stringWithFormat:@"%ld",_starNUm] forKey:[_fieldSetArr[4] objectForKey:@"montageName"]];
    if (_hiddenArr.count>0) {
        
        [_keyValueClass setHiddens:_hiddenArr andSendDic:_sendDic andMana:nil andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman) {
            _sendDic = send;
        }];   // setHiddenArr:_hiddenArr
        
        //        [self setHiddens];
    }
    
    NSLog(@"%@",_sendDic);
    
    NSString *relationStr = [NSString stringWithFormat:@"t0_au_%@_%@_%@", tableId, pageId, self.relationId];
    
    if([[NSString stringWithFormat:@"%@", [_buttonDIc valueForKey:@"buttonType"]]isEqualToString:@"18"]){  // 关联添加必须键因为不是关联添加默认值将不显示
        [_sendDic setObject:[_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]] forKey:relationStr];
    }
    
    
    [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:YES];
    
    
    NSString *str = [self fieldDicToString:_sendDic];
    NSMutableString *lastUrl = [NSMutableString stringWithFormat:@"%@%@?%@",self.programaUrl, ADD_Commit_URL,str];
    
    
    if([lastUrl hasPrefix:@"http://182.92.74.232:9994"]){
        NSArray *arr = [lastUrl componentsSeparatedByString:@"182.92.74.232:9994"];
        lastUrl = [NSMutableString stringWithFormat:@"%@%@%@", arr[0], @"182.92.108.162:8124", arr[1]];
    }
    
    
    NSString * urlString= [lastUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url_str=[NSURL URLWithString:urlString];
    
    
    
    
    //    NSArray *arr = [_sendMutDic allKeys];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url_str];
    //    3.发送请求
    //发送异步请求，在主线程执行
    NSOperationQueue *queue=[NSOperationQueue mainQueue];
    
    
    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        if(data!=nil&&!connectionError){
            NSString *dataStr=  [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"dataString --------------------      %@ --------------------", dataStr);
#pragma mark - 登录超时返回登录页
            NSRange range = [dataStr rangeOfString:@"登录超时"];
            
            if (range.location != NSNotFound) {
                [self sessionIsOverTime:dataStr];
                return;
            }
#pragma mark - 登录超时end
            if(![dataStr isEqualToString:@"0"]&&dataStr.length>0){// 不知道咋回事 之前 是 1 但是现在我感觉 不为 0 就行 返回的是 数据的条数
                
                //*** post the notifacation center should reload list view controller
                [[NSNotificationCenter defaultCenter]postNotificationName:@"shouldReload" object:@"ok"];
                
                _alert =[[UIAlertView alloc]initWithTitle:nil message:@"评价成功" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
                [_alert show];
                [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
                
               
                
                //*** hidden the netWork state activity
                [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
                
            }
            
            else{
                _sureEvalute.userInteractionEnabled = YES;
//                _alert =[[UIAlertView alloc]initWithTitle:nil message:@"添加失败" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
//                [_alert show];
//                [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
//                
//                self.subBtn.enabled = YES;
//                addSucceed = NO;
                
                //*** hidden the netWork state activity
                [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
                
            }
        }else{
            [self showLabelWithText:@"网络错误"];
            
            //*** hidden the netWork state activity
            [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
            
        }
    }];
    
}


-(void) performDismiss:(NSTimer *)timer
{
    [_alert dismissWithClickedButtonIndex:0 animated:NO];
    
        if (self.retureView) {
            NSArray *arr = self.navigationController.viewControllers;
            
            for (id  viewController in arr) {
                if ([viewController isKindOfClass:[self.retureView class]]) {
                    [self.navigationController popToViewController:viewController animated:YES];
                    return;
                    
                }
            }
        }else{
            [self.navigationController popViewControllerAnimated:YES];
        }
    
    
    
}


#pragma mark - dic  to NSString
-(NSString *)fieldDicToString:(NSDictionary *)dic{
    
    NSString *str = @"";
    NSMutableArray *muArr =[NSMutableArray array];
    NSArray *arr = [dic allKeys];
    NSArray *arr1 =[dic allValues];
    for(int i=0;i<arr.count;i++){
        NSString *string = [NSString stringWithFormat:@"%@=%@",arr[i],arr1[i]];
        [muArr addObject:string];
    }
    NSString *str1 =[muArr componentsJoinedByString:@"&&"];
    str = str1;
        return str;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
